package com.note;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.ikang.idata.common.entity.EleOverallTrendFilm;
import com.ikang.idata.common.entity.vo.EleOverallTrendResult;
import com.ikang.idata.common.entity.vo.EleOverallTrendVo;
import com.ikang.idata.common.utils.CalculateUtil;
import com.ikang.idata.common.utils.DecimalFormatUtil;
import com.ikang.idata.common.utils.QuarterUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.ikang.idata.common.consts.MagicConst.COMMA_SPLIT;

/**
 * @author: hao.liu
 * @Date: 2021/8/8 09:40
 */
@Slf4j
@Service
public class EleOverallTrendServiceNew {

    @Autowired
    EleOverallTrendKanbanService eleOverallTrendKanbanService;

    public static final String ZERO_POINT_ZERO = "0.0";

    public static final String ZERO = "0";
    /**
     * @description: 概览-整体趋势统计-展示
     *
     * @param eleOverallTrendVo 电商看板-整体趋势VO
     * @return com.ikang.idata.common.entity.vo.EleOverallTrendResult
     * @auther yanan.mu-ext
     * @date 2022-02-23 下午2:35
     */
    public EleOverallTrendResult getTotalTrend(EleOverallTrendVo eleOverallTrendVo) {
        int year = eleOverallTrendVo.getYear();
        LocalDate now = LocalDate.now();
        if (0 >= year || 0 == eleOverallTrendVo.getMonthOrQ()) {
            year = now.getYear();
        }
        String[] localDate;
        String[] YOY;
        String[] QOQ;
        if (0 == eleOverallTrendVo.getFilterType()) {
            //季度
            localDate = QuarterUtils.getQuarterByYear(year, eleOverallTrendVo.getMonthOrQ());
            int monthOrQ = eleOverallTrendVo.getMonthOrQ();
            if (0 == monthOrQ) {
                monthOrQ = Integer.parseInt(localDate[3]);
            }
            //同比
            YOY = QuarterUtils.getQuarterByYear(year - 1, monthOrQ);
            //环比
            if (monthOrQ - 1 == 0) {
                QOQ = QuarterUtils.getQuarterByYear(year - 1, 4);
            } else {
                QOQ = QuarterUtils.getQuarterByYear(year, monthOrQ - 1);
            }
        } else  if (1 == eleOverallTrendVo.getFilterType()) {
            //月份
            //当月
            int monthOrQ = eleOverallTrendVo.getMonthOrQ();
            if (0 == monthOrQ) {
                now = now.plusDays(-1);
                monthOrQ = now.getMonthValue();
            }
            LocalDate of = LocalDate.of(year, monthOrQ, 1);
            DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String firstday = of.with(TemporalAdjusters.firstDayOfMonth()).format(fmt) + " 00:00:00";
            String lastDay = of.with(TemporalAdjusters.lastDayOfMonth()).format(fmt) + " 23:59:59";
            String yearAndMonth = year + "年" + monthOrQ + "月";
            localDate = new String[]{firstday, lastDay, yearAndMonth};
            //同比
            LocalDate YOYDate = of.plusYears(-1);
            String firstdayYOY = YOYDate.with(TemporalAdjusters.firstDayOfMonth()).format(fmt) + " 00:00:00";
            String lastDayYOY = YOYDate.with(TemporalAdjusters.lastDayOfMonth()).format(fmt) + " 23:59:59";
            String yearAndMonthYOY = YOYDate.getYear() + "年" + YOYDate.getMonthValue() + "月";
            YOY = new String[]{firstdayYOY, lastDayYOY, yearAndMonthYOY};
            //环比
            LocalDate QOQDate = of.plusMonths(-1);
            String firstdayQOQ = QOQDate.with(TemporalAdjusters.firstDayOfMonth()).format(fmt) + " 00:00:00";
            String lastDayQOQ = QOQDate.with(TemporalAdjusters.lastDayOfMonth()).format(fmt) + " 23:59:59";
            String yearAndMonthQOQ = QOQDate.getYear() + "年" + QOQDate.getMonthValue() + "月";
            QOQ = new String[]{firstdayQOQ, lastDayQOQ, yearAndMonthQOQ};
        } else {
            //按年  年份 有没有更好的方法
            //获取到当年的年份
            int localYear = eleOverallTrendVo.getYear();
            //拼装年份完整时间 开始    结束
            String yearStart = "-04-01 00:00:00";
            String yearEnd = "-03-31 23:59:59";
            localDate = new String[]{(localYear + yearStart), (localYear + 1)+yearEnd, localYear + "财年", ""};
            //同比时间 开始
            YOY = new String[]{(localYear -1)+ yearStart, (localYear + yearEnd), (localYear -1) + "财年", ""};
            //同比时间 就是环比时间
            QOQ = YOY;
        }

        List<EleOverallTrendFilm> results = new ArrayList<>();

        String channels = eleOverallTrendVo.getPurchaseChannelCode();
        List<String> channelList = StrUtil.isNotBlank(channels) ? CollUtil.newArrayList(channels.split(COMMA_SPLIT)) : null;

        //计算 选中时间段的累计值
        EleOverallTrendResult localDateValue = eleOverallTrendKanbanService.getTime(channelList, localDate[0], localDate[1]);
        List<Map<String, Object>> allList = localDateValue.getAllList();
        BigDecimal saleAmount = BigDecimal.ZERO;
        BigDecimal incomeAmount = BigDecimal.ZERO;
        BigDecimal cancelCome = BigDecimal.ZERO;
        BigDecimal saleNum = BigDecimal.ZERO;
        BigDecimal saleCardPrice = BigDecimal.ZERO;
        BigDecimal salePhone = BigDecimal.ZERO;
        BigDecimal personalNum = BigDecimal.ZERO;
        BigDecimal salePhonePrice = BigDecimal.ZERO;
        BigDecimal regNum = BigDecimal.ZERO;
        BigDecimal checkNum = BigDecimal.ZERO;
        BigDecimal reportNum = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(localDateValue.getList())) {

            saleAmount = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            incomeAmount = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getIncomeAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            cancelCome = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getCancelCome)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            saleNum = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            saleCardPrice = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleCardPrice)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            salePhone = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getSalePhone)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            personalNum = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getPersonalNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            salePhonePrice = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getSalePhonePrice)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            regNum = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getRegNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            checkNum = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getCheckNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            reportNum = localDateValue.getList().stream()
                    .map(EleOverallTrendFilm::getReportNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);

        }
        //环比 时间的累计值和
        EleOverallTrendResult QOQDataValue = eleOverallTrendKanbanService.getTime(channelList, QOQ[0], QOQ[1]);
        BigDecimal saleAmountQOQ = BigDecimal.ZERO;
        BigDecimal incomeAmountQOQ = BigDecimal.ZERO;
        BigDecimal cancelComeQOQ = BigDecimal.ZERO;
        BigDecimal saleNumQOQ = BigDecimal.ZERO;
        BigDecimal salePhoneQOQ = BigDecimal.ZERO;
        BigDecimal personalNumQOQ = BigDecimal.ZERO;
        BigDecimal regNumQOQ = BigDecimal.ZERO;
        BigDecimal checkNumQOQ = BigDecimal.ZERO;
        BigDecimal reportNumQOQ = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(QOQDataValue.getList())) {

            saleAmountQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            incomeAmountQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getIncomeAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            cancelComeQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getCancelCome)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            saleNumQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            salePhoneQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSalePhone)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            personalNumQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getPersonalNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            regNumQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getRegNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            checkNumQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getCheckNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            reportNumQOQ = QOQDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getReportNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);

        }

        //同比  时间的累计值和
        EleOverallTrendResult YOYDataValue = eleOverallTrendKanbanService.getTime(channelList, YOY[0], YOY[1]);
        BigDecimal saleAmountYOY = BigDecimal.ZERO;
        BigDecimal incomeAmountYOY = BigDecimal.ZERO;
        BigDecimal cancelComeYOY = BigDecimal.ZERO;
        BigDecimal saleNumYOY = BigDecimal.ZERO;
        BigDecimal saleCardPriceYOY = BigDecimal.ZERO;
        BigDecimal salePhoneYOY = BigDecimal.ZERO;
        BigDecimal personalNumYOY = BigDecimal.ZERO;
        BigDecimal regNumYOY = BigDecimal.ZERO;
        BigDecimal checkNumYOY = BigDecimal.ZERO;
        BigDecimal reportNumYOY = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(YOYDataValue.getList())) {

            saleAmountYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            incomeAmountYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getIncomeAmount)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            cancelComeYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getCancelCome)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            saleNumYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            saleCardPriceYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSaleCardPrice)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            salePhoneYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getSalePhone)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            personalNumYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getPersonalNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            regNumYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getRegNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            checkNumYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getCheckNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
            reportNumYOY = YOYDataValue.getList().stream()
                    .map(EleOverallTrendFilm::getReportNum)
                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);

        }
        //第一部分
        //累计销售额
        List<EleOverallTrendFilm.Piece> pieceArrayList = new ArrayList<>();
        EleOverallTrendFilm.Piece saleAmountPiece = new EleOverallTrendFilm.Piece();
        saleAmountPiece.setHeader("累计销售额");
        //当前时间没有
        saleAmountPiece.setDate(localDate[2]);
        //拿到当前的值
        String[] saleAmountStr = CalculateUtil.getNumberWanTwo(saleAmount.toString(),"元");
        saleAmountPiece.setValue(saleAmountStr[0]);
        //单位 元  要进行处理?
        saleAmountPiece.setUnit(saleAmountStr[1]);
        //环比值 没有
        saleAmountPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleAmount.toString(), saleAmountQOQ.toString())));
        //环比升降类型
        saleAmountPiece.setRingRatioType(String.valueOf(saleAmount.compareTo(saleAmountQOQ)));
        //同比值 没有
        saleAmountPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleAmount.toString(), saleAmountYOY.toString())));
        //同比升降类型
        saleAmountPiece.setYearOnYearType(String.valueOf(saleAmount.compareTo(saleAmountYOY)));
        saleAmountPiece.setRemark("注：已扣除退款");
        pieceArrayList.add(saleAmountPiece);


        //累计日收入 选中的时间值
        EleOverallTrendFilm.Piece incomeAmountPiece = new EleOverallTrendFilm.Piece();
        incomeAmountPiece.setHeader("累计收入");
        //当前时间没有
        incomeAmountPiece.setDate(localDate[2]);
        //拿到当前的值
        String[] incomeAmountStr = CalculateUtil.getNumberWanTwo(incomeAmount.toString(),"元");
        incomeAmountPiece.setValue(incomeAmountStr[0]);
        //单位 元  要进行处理?
        incomeAmountPiece.setUnit(incomeAmountStr[1]);
        incomeAmountPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(incomeAmount.toString(), incomeAmountQOQ.toString())));
        incomeAmountPiece.setRingRatioType(String.valueOf(incomeAmount.compareTo(incomeAmountQOQ)));
        incomeAmountPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(incomeAmount.toString(), incomeAmountYOY.toString())));
        incomeAmountPiece.setYearOnYearType(String.valueOf(incomeAmount.compareTo(incomeAmountYOY)));
        incomeAmountPiece.setRemark("注：当前仅包含“体检业务”到检状态收入");
        pieceArrayList.add(incomeAmountPiece);

        //累计退款
        //累计日收入 选中的时间值
        EleOverallTrendFilm.Piece cancelComePiece = new EleOverallTrendFilm.Piece();
        cancelComePiece.setHeader("累计退款");
        //当前时间没有
        cancelComePiece.setDate(localDate[2]);
        //拿到当前的值
        String[] cancelComePieceStr = CalculateUtil.getNumberWanTwo(cancelCome.toString(),"元");
        cancelComePiece.setValue(cancelComePieceStr[0]);
        //单位 元  要进行处理?
        cancelComePiece.setUnit(cancelComePieceStr[1]);
        cancelComePiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(cancelCome.toString(), cancelComeQOQ.toString())));
        cancelComePiece.setRingRatioType(String.valueOf(cancelCome.compareTo(cancelComeQOQ)));
        cancelComePiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(cancelCome.toString(), cancelComeYOY.toString())));
        cancelComePiece.setYearOnYearType(String.valueOf(cancelCome.compareTo(cancelComeYOY)));
        cancelComePiece.setRemark("注：阿里健康由于特殊原因无法计算退款");
        pieceArrayList.add(cancelComePiece);


        //第二部分
        //累计售出商品
        List<EleOverallTrendFilm.Piece> productDataList = new ArrayList<>();
        EleOverallTrendFilm.Piece saleNumPiece = new EleOverallTrendFilm.Piece();
        saleNumPiece.setHeader("累计售出商品");
        //当前时间没有
        saleNumPiece.setDate(localDate[2]);
        //拿到当前的值
        // 不到万元的时候  没有小数点   单位进制后 保留两位小数点
        String[] saleNumStr = CalculateUtil.getNumberDeal(saleNum.toString(),"件");
        saleNumPiece.setValue(saleNumStr[0]);
        //单位 元  要进行处理?
        saleNumPiece.setUnit(saleNumStr[1]);
        saleNumPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleNum.toString(), saleNumQOQ.toString())));
        saleNumPiece.setRingRatioType(String.valueOf(saleNum.compareTo(saleNumQOQ)));
        saleNumPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleNum.toString(), saleNumYOY.toString())));
        saleNumPiece.setYearOnYearType(String.valueOf(saleNum.compareTo(saleNumYOY)));
        saleNumPiece.setRemark("注：商品数量根据卡的数量统计");
        productDataList.add(saleNumPiece);


        //件单价  需要计算  为计算 "sale_card_price" : 1000.0,（件单价） saleAmount/saleNum
        EleOverallTrendFilm.Piece saleCardPricePiece = new EleOverallTrendFilm.Piece();
        saleCardPricePiece.setHeader("件单价");
        //当前时间没有
        saleCardPricePiece.setDate(localDate[2]);
        //拿到当前的值
        BigDecimal saleCardPricebigDecimal = MallDashBoardService.isZero(saleNum.toString()) ? new BigDecimal("0") : NumberUtil.div(saleAmount, saleNum);
        saleCardPricePiece.setValue(DecimalFormatUtil.TWO_DECIMAL_PLACE_FORMAT.format(saleCardPricebigDecimal));
        //单位 元
        saleCardPricePiece.setUnit("元");
        saleCardPricePiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleCardPrice.toString(), saleCardPrice.toString())));
        saleCardPricePiece.setRingRatioType(String.valueOf(saleCardPrice.compareTo(saleCardPrice)));
        saleCardPricePiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(saleCardPrice.toString(), saleCardPriceYOY.toString())));
        saleCardPricePiece.setYearOnYearType(String.valueOf(saleCardPrice.compareTo(saleCardPriceYOY)));
        saleCardPricePiece.setRemark("注：采用卡类商品总销售额/卡数量");
        productDataList.add(saleCardPricePiece);


        //第三部分
        //累计购买订单 "sale_phone" : 1,（订单数量）
        List<EleOverallTrendFilm.Piece> orderList = new ArrayList<>();
        EleOverallTrendFilm.Piece salePhonePiece = new EleOverallTrendFilm.Piece();
        salePhonePiece.setHeader("累计购买订单");
        //当前时间没有
        salePhonePiece.setDate(localDate[2]);
        //拿到当前的值
        String[] salePhoneStr = CalculateUtil.getNumberDeal(salePhone.toString(),"个");

        salePhonePiece.setValue(salePhoneStr[0]);
        salePhonePiece.setUnit(salePhoneStr[1]);
        salePhonePiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(salePhone.toString(), salePhoneQOQ.toString())));
        salePhonePiece.setRingRatioType(String.valueOf(salePhone.compareTo(salePhoneQOQ)));
        salePhonePiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(salePhone.toString(), salePhoneYOY.toString())));
        salePhonePiece.setYearOnYearType(String.valueOf(salePhone.compareTo(salePhoneYOY)));
        salePhonePiece.setRemark("注：通过购买订单号去重后计算");
        orderList.add(salePhonePiece);


        //  单均价  需要计算  为计算  "personal_num" : 4.0,（单均件数）saleAmount/salePhone
        EleOverallTrendFilm.Piece personalNumPiece = new EleOverallTrendFilm.Piece();
        personalNumPiece.setHeader("单均件数");
        //当前时间没有
        personalNumPiece.setDate(localDate[2]);
        BigDecimal personalNumbigDecimal = MallDashBoardService.isZero(salePhone.toString()) ? new BigDecimal("0") : NumberUtil.div(saleNum, salePhone);
        personalNumPiece.setValue(DecimalFormatUtil.TWO_DECIMAL_PLACE_FORMAT.format(personalNumbigDecimal));
        //单位 元
        personalNumPiece.setUnit("件");
        //除数中有0 的存在
        personalNumPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(personalNum.toString(), personalNumQOQ.toString())));
        personalNumPiece.setRingRatioType(String.valueOf(personalNum.compareTo(personalNumQOQ)));
        personalNumPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(personalNum.toString(), personalNumYOY.toString())));
        personalNumPiece.setYearOnYearType(String.valueOf(personalNum.compareTo(personalNumYOY)));
        personalNumPiece.setRemark("注：通过商品件数和购买订单数计算");
        orderList.add(personalNumPiece);

        //  单均件数  需要计算  为计算   "sale_phone_price" : 4000.0,（单均价）
        EleOverallTrendFilm.Piece salePhonePricePiece = new EleOverallTrendFilm.Piece();
        salePhonePricePiece.setHeader("单均价");
        //当前时间没有
        salePhonePricePiece.setDate(localDate[2]);
        //拿到当前的值
        BigDecimal salePhonePricebigDecimal = MallDashBoardService.isZero(salePhone.toString()) ? new BigDecimal("0") : NumberUtil.div(saleAmount, salePhone);
        salePhonePricePiece.setValue(DecimalFormatUtil.TWO_DECIMAL_PLACE_FORMAT.format(salePhonePricebigDecimal));
        //单位 元  要进行处理?
        salePhonePricePiece.setUnit("元");
        salePhonePricePiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(salePhonePrice.toString(), saleAmountQOQ.toString())));
        salePhonePricePiece.setRingRatioType(String.valueOf(salePhonePrice.compareTo(saleAmountQOQ)));
        salePhonePricePiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(salePhonePrice.toString(), saleAmountYOY.toString())));
        salePhonePricePiece.setYearOnYearType(String.valueOf(salePhonePrice.compareTo(saleAmountYOY)));
        salePhonePricePiece.setRemark("注：通过销售额和购买订单数计算");
        orderList.add(salePhonePricePiece);

        //

        //第四部分
        //累计预约人数
        List<EleOverallTrendFilm.Piece> serviceDataList = new ArrayList<>();
        EleOverallTrendFilm.Piece regNumPiece = new EleOverallTrendFilm.Piece();
        regNumPiece.setHeader("累计预约人数");
        //当前时间没有
        regNumPiece.setDate(localDate[2]);
        //拿到当前的值
        String[] regNumStr = CalculateUtil.getNumberDeal(regNum.toString(),"人");
        regNumPiece.setValue(regNumStr[0]);
        //单位 元  要进行处理?
        regNumPiece.setUnit(regNumStr[1]);
        regNumPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(regNum.toString(), regNumQOQ.toString())));
        regNumPiece.setRingRatioType(String.valueOf(regNum.compareTo(regNumQOQ)));
        regNumPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(regNum.toString(), regNumYOY.toString())));
        regNumPiece.setYearOnYearType(String.valueOf(regNum.compareTo(regNumYOY)));
        regNumPiece.setRemark("注：按照客户下预约单的时间进行计算");
        serviceDataList.add(regNumPiece);


        //累计到检人数
        EleOverallTrendFilm.Piece checkNumPiece = new EleOverallTrendFilm.Piece();
        checkNumPiece.setHeader("累计到检人数");
        //当前时间没有
        checkNumPiece.setDate(localDate[2]);
        //拿到当前的值
        String[] checkNumStr = CalculateUtil.getNumberDeal(checkNum.toString(),"人");
        checkNumPiece.setValue(checkNumStr[0]);
        //单位 元  要进行处理?
        checkNumPiece.setUnit(checkNumStr[1]);
        checkNumPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(checkNum.toString(), checkNumQOQ.toString())));
        checkNumPiece.setRingRatioType(String.valueOf(checkNum.compareTo(checkNumQOQ)));
        checkNumPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(checkNum.toString(), checkNumYOY.toString())));
        checkNumPiece.setYearOnYearType(String.valueOf(checkNum.compareTo(checkNumYOY)));
        checkNumPiece.setRemark("注：按照已到检的卡数量计算");
        serviceDataList.add(checkNumPiece);

        //累计出具报告人数
        EleOverallTrendFilm.Piece reportNumPiece = new EleOverallTrendFilm.Piece();
        reportNumPiece.setHeader("累计出具报告人数");
        //当前时间没有
        reportNumPiece.setDate(localDate[2]);
        //拿到当前的值
        String[] reportNumStr = CalculateUtil.getNumberDeal(reportNum.toString(),"人");
        reportNumPiece.setValue(reportNumStr[0]);
        //单位 元  要进行处理?
        reportNumPiece.setUnit(reportNumStr[1]);
        reportNumPiece.setRingRatio(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(reportNum.toString(), reportNumQOQ.toString())));
        reportNumPiece.setRingRatioType(String.valueOf(reportNum.compareTo(reportNumQOQ)));
        reportNumPiece.setYearOnYear(DecimalFormatUtil.PERCENT_SIGN_FORMAT.format(CalculateUtil.synchronousCalculation(reportNum.toString(), reportNumYOY.toString())));
        reportNumPiece.setYearOnYearType(String.valueOf(reportNum.compareTo(reportNumYOY)));
        reportNumPiece.setRemark("注：按照出具报告的卡数量计算");
        serviceDataList.add(reportNumPiece);


        //4部分
        results.add(new EleOverallTrendFilm().setTypeName("交易数据").setPieces(pieceArrayList));
        results.add(new EleOverallTrendFilm().setTypeName("商品数据").setPieces(productDataList));
        results.add(new EleOverallTrendFilm().setTypeName("订单数据").setPieces(orderList));
        results.add(new EleOverallTrendFilm().setTypeName("服务数据").setPieces(serviceDataList));


        EleOverallTrendResult eleOverallTrendResult = new EleOverallTrendResult();
        eleOverallTrendResult.setList(results);
        eleOverallTrendResult.setAllList(allList);
        return eleOverallTrendResult;
    }

}
